﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Web;
using System.Xml;
using DBBase;

namespace Business
{
    public partial class personnel18C05 : Form
    {
        public MainForm m_mainform;

        public string ssqm="";

        public personnel18C05()
        {
            InitializeComponent();
        }

        private void but_download_Click(object sender, EventArgs e)
        {
            string vehispara = "";
            string stoubao = "<?xml version=\"1.0\" encoding=\"GBK\"?>";
            vehispara = stoubao + string.Format("<root><QueryCondition><sfzmhm>{0}</sfzmhm><xm>{1}</xm><jczbh>{2}</jczbh><gxrq>{3}</gxrq></QueryCondition></root>",
                tb_sfzhm.Text,
                tb_name.Text,
                tb_jcjgbh.Text,
                 dateTimePicker1.Value.ToString("yyyy-MM-dd"));

            WebReference.Service m_sshenhe18C50 = new WebReference.Service();
            string str = decode(m_sshenhe18C50.queryObjectOut("18", m_mainform.sSQM, "18C05", vehispara));
            MessageBox.Show(str);
            if (str.Length < 1)
            {
                MessageBox.Show("连接不到服务器");

            }
            else
            {
                XmlDocument xmlstr = new XmlDocument();
                xmlstr.LoadXml(str);
                if (xmlstr.SelectSingleNode("/root/head/code").InnerText == "1")
                {
                    tb_sfzhm.Text = xmlstr.SelectSingleNode("/root/body/vehispara/sfzmhm").InnerText;
                    tb_name.Text = xmlstr.SelectSingleNode("/root/body/vehispara/xm").InnerText;
                }
                Query mquery = new Query();
                string sql = string.Format("select * from table_ry where sfzmhm='{0}'", xmlstr.SelectSingleNode("/root/body/vehispara/sfzmhm").InnerText);
                DataTable dt = mquery.GetTable(sql);
                if (dt.Rows.Count > 0)
                {
                    
                }
                else
                {
                    sql = string.Format(@"Insert Into table_ry (sfzmhm,
                                                        xm,
                                                        hphm,
                                                        rylb,
                                                        glbm,
                                                        fzjg,
                                                        jczbh,
                                                        gxrq,
                                                        bz,
                                                        shbj,
                                                        shyj,
                                                        zt,
                                                        sgzbh,
                                                        sgzyxqz,
                                                        sgzffdw,
                                                        syglbm)
                                                        Values(
                                                        '{0}',
                                                        '{1}',
                                                        '{2}',
                                                        '{3}',
                                                        '{4}',
                                                        '{5}',
                                                        '{6}',
                                                        '{7}',
                                                        '{8}',
                                                        '{9}',
                                                        '{10}',
                                                        '{11}',
                                                        '{12}',
                                                        '{13}',
                                                        '{14}')",
                     xmlstr.SelectSingleNode("/root/body/vehispara/sfzmhm").InnerText,
                     xmlstr.SelectSingleNode("/root/body/vehispara/xm").InnerText,
                     xmlstr.SelectSingleNode("/root/body/vehispara/rylb").InnerText,
                     xmlstr.SelectSingleNode("/root/body/vehispara/glbm").InnerText,
                     xmlstr.SelectSingleNode("/root/body/vehispara/fzjg").InnerText,
                     xmlstr.SelectSingleNode("/root/body/vehispara/jczbh").InnerText,
                     xmlstr.SelectSingleNode("/root/body/vehispara/gxrq").InnerText,
                     xmlstr.SelectSingleNode("/root/body/vehispara/bz").InnerText,
                     xmlstr.SelectSingleNode("/root/body/vehispara/shbj").InnerText,
                     xmlstr.SelectSingleNode("/root/body/vehispara/shyj").InnerText,
                     xmlstr.SelectSingleNode("/root/body/vehispara/zt").InnerText,
                     xmlstr.SelectSingleNode("/root/body/vehispara/sgzbh").InnerText,
                     xmlstr.SelectSingleNode("/root/body/vehispara/sgzyxqz").InnerText,
                     xmlstr.SelectSingleNode("/root/body/vehispara/sgzffdw").InnerText,
                     xmlstr.SelectSingleNode("/root/body/vehispara/syglbm").InnerText);
                }
                mquery.InsertDB(sql);
                getdate();
            }

        }

        public string decode(string str)//utf8转中文
        {
            Encoding utf8 = Encoding.UTF8;
            // 首先用utf-8进行解码                    
            return HttpUtility.UrlDecode(str.ToUpper(), utf8);
        }

        private void personnel18C05_Load(object sender, EventArgs e)
        {
            getdate();
        }

        public void getdate()
        {
            Query mquery = new Query();
            string sql = string.Format("select * from table_ry");
            DataTable dt = mquery.GetTable(sql);
            if (dt.Rows.Count > 0)
            {

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    ListViewItem lt = new ListViewItem(string.Format("{0}", i));
                    lt.SubItems.Add(dt.Rows[i]["sfzmhm"].ToString().Trim());
                    lt.SubItems.Add(dt.Rows[i]["xm"].ToString().Trim());
                    lt.SubItems.Add(dt.Rows[i]["rylb"].ToString().Trim());
                    lt.SubItems.Add(dt.Rows[i]["glbm"].ToString().Trim());
                    lt.SubItems.Add(dt.Rows[i]["fzjg"].ToString().Trim());
                    lt.SubItems.Add(dt.Rows[i]["jczbh"].ToString().Trim());
                    lt.SubItems.Add(dt.Rows[i]["gxrq"].ToString().Trim());
                    lt.SubItems.Add(dt.Rows[i]["bz"].ToString().Trim());
                    lt.SubItems.Add(dt.Rows[i]["shbj"].ToString().Trim());
                    lt.SubItems.Add(dt.Rows[i]["shyj"].ToString().Trim());
                    lt.SubItems.Add(dt.Rows[i]["zt"].ToString().Trim());
                    lt.SubItems.Add(dt.Rows[i]["sgzbh"].ToString().Trim());
                    lt.SubItems.Add(dt.Rows[i]["sgzyxqz"].ToString().Trim());
                    lt.SubItems.Add(dt.Rows[i]["sgzffdw"].ToString().Trim());
                    lt.SubItems.Add(dt.Rows[i]["syglbm"].ToString().Trim());
                    this.lv.Items.Add(lt);

                }
            }
        
        }
    }
}
